import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/pages/login/login'
import Student from '@/pages/Student/Student.vue'
import Teacher from '@/pages/Teacher/TeacherHome'
import Grade from '@/pages/Teacher/components/Grade'
import wrong_book from '@/pages/Teacher/components/wrong_book'
import AddTest from '@/pages/Teacher/components/AddTest'
import Exam from '@/pages/Student/components/exam'
import onlineExam from '@/pages/Student/components/onlineExam'
Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'Login',
      component: Login
    }, 
    //学生页面
    {
      path: '/Student',
      name: 'Student',
      component: Student,
      children: [{
        path: '/student/exam',
        name: 'Exam',
        component: Exam,
      }, {
        path: '/AddTest',
        name: 'AddTest',
        component: AddTest,
      }, {
        path: '/wrong_book',
        name: 'wrong_book',
        component: wrong_book,
      },
      {
        path: '/onlineExam',
        name: 'onlineExam',
        component: onlineExam,
      }]
    },
    //教师页面
     {
      path: '/teacher',
      name: 'Teacher',
      component: Teacher,
      //教师页面的子页面中的成绩页面
      children: [{
        path: '/grade',
        name: 'Grade',
        component: Grade,
      }, {
        path: '/AddTest',
        name: 'AddTest',
        component: AddTest,
      }, {
        path: '/wrong_book',
        name: 'wrong_book',
        component: wrong_book,
      }
      ]
    },
    //管理员页面
    {
      path:'/manager',
      name:'Manager',
      component:()=>import('@/pages/Manager/ManagerHome.vue'),
      children: [{
        path: '/grade',
        name: 'Grade',
        component: Grade,
      }, {
        path: '/Mstudent',
        name: 'Mstudent',
        component:()=>import('@/pages/Manager/components/Mstudent.vue')
      }, {
        path: '/Mteacher',
        name: 'Mteacher',
        component:()=>import('@/pages/Manager/components/Mteacher.vue'),
      }
      ]
    }

  ]
})

// //挂载路由导航守卫
// router.beforeEach((to, form, next) => {
//   //to 将要访问的路径
//   //form 代表从哪个路径跳转来
//   //next 是一个函数，表示放行
//   //next()放行，next('/login) 强制跳转
//   if (to.path == '/login')
//     return next()
//   //获取token
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (!tokenStr) { return next('/login') }
//   else {
//     next()
//   }

// })
export default router
